package com.demo.java.OD101_150.OD123;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

/**
 * @author bug菌
 * @Source 公众号：猿圈奇妙屋
 * @des： 【分界线】问题
 * @url： https://blog.csdn.net/weixin_43970743/article/details/145721298
 */
public class OdMain {
    public static void main(String[] args) {
        try {
            Scanner scan = new Scanner(System.in);
            String newspaper = scan.nextLine();  // 输入报纸内容
            // 判断数据合法性
            if (newspaper == null || newspaper.length() == 0 || newspaper.length() > 10 * 10 * 10 * 10) {
                System.out.println("input error");
                return;
            }
            String anonymousLetter = scan.nextLine();  // 输入匿名信内容
            // 判断数据合法性
            if (anonymousLetter == null || anonymousLetter.length() == 0
                    || anonymousLetter.length() > 10 * 10 * 10 * 10) {
                System.out.println("input error");
                return;
            }
            List<String> newspaperStrList = getSortList(newspaper);  // 获取排序后的报纸字符串列表
            // 判断数据合法性
            if (newspaperStrList == null) {
                System.out.println("input error");
                return;
            }
            List<String> anonymousLetterStrList = getSortList(anonymousLetter);  // 获取排序后的匿名信字符串列表
            // 判断数据合法性
            if (anonymousLetterStrList == null) {
                System.out.println("input error");
                return;
            }
            boolean result = true;
            // 对比匿名信中的每个字母是否能在报纸中找到
            for (String s : anonymousLetterStrList) {
                if (!newspaperStrList.contains(s)) {
                    result = false;
                    break;
                }
            }
            System.out.print(result);  // 输出结果
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("input error");
        }
    }

    // 将字符串进行按字母排序的处理
    private static List<String> getSortList(String newspaper) {
        if (newspaper == null || newspaper.length() == 0)
            return null;
        List<String> newsPaperList = new ArrayList<>();
        String[] strs = newspaper.split(" ");  // 以空格分割字符串
        int length = strs.length;
        if (length >= 100)  // 字符串单词数不能超过100
            return null;

        // 对每个单词的字符进行排序
        for (String s : strs) {
            char[] values = s.toCharArray();  // 转换为字符数组
            Arrays.sort(values);  // 排序
            String str = new String(values);  // 排序后转换回字符串
            newsPaperList.add(str);  // 添加到列表中
        }
        return newsPaperList;
    }
}